package com.weetop.cfw.base.presenter.imp

import com.weetop.cfw.base.presenter.KindPresenter
import com.weetop.cfw.base.view.BaseView
import com.weetop.cfw.base.view.KindView
import com.weetop.cfw.bean.AreaBean
import com.weetop.cfw.bean.GeneralCodeTableBean
import com.weetop.cfw.bean.KindBean
import com.weetop.cfw.bean.SiteBean
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.constants.Constants
import com.weetop.cfw.kind.fragment.KindFragment
import com.weetop.cfw.utils.RetrofitUtils
import com.weetop.cfw.utils.RxJavaUtils

class KindPresenterImp(var kindView: KindView ?= null): KindPresenter {

    /**
     * 获取分类的数据
     */
    override fun getKindData(kindFragment: KindFragment) {
        RxJavaUtils.useInSupportFragmentOnDestoryView(RetrofitUtils.getApi().kind(),kindFragment,object:
            RxJavaCallBack<KindBean>(){
            override fun onSuccess(t: KindBean?) {
                kindView?.kindDataGetSuccess(t)
            }
        })
    }

    /**
     * 获取面积的数据
     */
    override fun getAreaData(kindFragment: KindFragment) {
        RxJavaUtils.useInSupportFragmentOnDestoryView(RetrofitUtils.getApi().generalCodeTable(1100),kindFragment,object:RxJavaCallBack<GeneralCodeTableBean>(){
            override fun onSuccess(t: GeneralCodeTableBean?) {
                kindView?.areaDataGetSuccess(t)
            }
        })
    }

    /**
     * 获取区域的数据
     */
    override fun getQuYuData(kindFragment: KindFragment) {
        RxJavaUtils.useInSupportFragmentOnDestoryView(RetrofitUtils.getApi().quYu(Constants.cityId),kindFragment,
            object : RxJavaCallBack<SiteBean>() {
                override fun onSuccess(t: SiteBean?) {
                    kindView?.quYuGetSuccess(t)
                }
            })
    }

    /**
     * 获取价格过滤的数据
     */
    override fun getPriceData(kindFragment: KindFragment) {
        RxJavaUtils.useInSupportFragmentOnDestoryView(RetrofitUtils.getApi().generalCodeTable(2300),kindFragment,object:RxJavaCallBack<GeneralCodeTableBean>(){
            override fun onSuccess(t: GeneralCodeTableBean?) {
                kindView?.priceFilterDataGetSuccess(t)
            }
        })
    }

    /**
     * 获取行业过滤的数据
     */
    override fun getIndustryData(kindFragment: KindFragment) {
        RxJavaUtils.useInSupportFragmentOnDestoryView(RetrofitUtils.getApi().generalCodeTable(1700),kindFragment,object:RxJavaCallBack<GeneralCodeTableBean>(){
            override fun onSuccess(t: GeneralCodeTableBean?) {
                kindView?.industryFilterDataGetSuccess(t)
            }
        })
    }

    /**
     * 获取来源过滤的数据
     */
    override fun getSourceData(kindFragment: KindFragment) {
        RxJavaUtils.useInSupportFragmentOnDestoryView(RetrofitUtils.getApi().generalCodeTable(1800),kindFragment,object:RxJavaCallBack<GeneralCodeTableBean>(){
            override fun onSuccess(t: GeneralCodeTableBean?) {
                kindView?.sourceFilterDataGetSuccess(t)
            }
        })
    }


    /**
     * 绑定
     */
    override fun attachView(baseView: BaseView) {
        kindView = baseView as? KindView
    }

    /**
     * 解绑
     */
    override fun detachView() {
        kindView = null
    }
}